//
//  WNAnimationManager.swift
//  WalkNovel
//
//  Created by Kevin on 2023/7/4.
//

import UIKit

extension UIButton {
    func wn_animation(_ array: [UIImage], _ duration: TimeInterval = 1, _ repeatCount: Int = 1) {
        imageView?.wn_animation(array, duration, repeatCount)
    }
}

extension UIImageView {
    func wn_animation(_ array: [UIImage], _ duration: TimeInterval = 1, _ repeatCount: Int = 1) {
        animationImages = array
        animationDuration = duration
        animationRepeatCount = repeatCount
    }
}

extension DispatchTime: ExpressibleByIntegerLiteral {
    public init(integerLiteral value: Int) {
        self = DispatchTime.now() + .seconds(value)
    }
}
extension DispatchTime: ExpressibleByFloatLiteral {
    public init(floatLiteral value: Double) {
        self = DispatchTime.now() + .milliseconds(Int(value * 1000))
    }
}

struct WNAnimation {
    /// 刷线加载动画
    static let wn_refLoadingArray: [UIImage] = {
        var array = [UIImage]()
        for i in 0..<25 {
            let name = String(format: "refresh_%d.png", i)
            array.append(UIImage(named: name)!.wn_resized(newSize: CGSize(width: 60, height: 60)))
        }
        return array
    }()
    
    /// 加载动画
    static let wn_loadingArray: [UIImage] = {
        var array = [UIImage]()
        for i in 0..<30 {
            let name = String(format: "loading_%d.png", i)
            array.append(UIImage(named: name)!.wn_resized(newSize: CGSize(width: 50, height: 50)))
        }
        return array
    }()
    
    // 音频正在播放
    static let wn_audoPlayingArray: [UIImage] = {
        var array = [UIImage]()
        for i in 65..<95 {
            let name = String(format: "音波_00%03d@3x.png", i)
            array.append(UIImage(named: name)!)
        }
        return array
    }()

}
